package com.zhida.smartcontrol.pagectrl.lampmanager.lampdetail.holiday;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

import com.jay.tools.utils.ResUtil;
import com.tan.indicator.FragmentContainerHelper;
import com.tan.indicator.MagicIndicator;
import com.tan.indicator.buildins.commonnavigator.CommonNavigator;
import com.tan.indicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import com.tan.indicator.buildins.commonnavigator.abs.IPagerIndicator;
import com.tan.indicator.buildins.commonnavigator.abs.IPagerTitleView;
import com.tan.indicator.buildins.commonnavigator.indicators.WrapPagerIndicator;
import com.tan.indicator.buildins.commonnavigator.titles.SimplePagerTitleView;
import com.tan.indicator.ext.titles.ColorFlipPagerTitleView;
import com.zhida.smartcontrol.R;
import com.zhida.smartcontrol.mvp.MVPBaseFragment;

import java.util.List;

import butterknife.BindView;

/**
 * author: tanjianpei
 * date: 2019/10/17 017 13:09
 * description: 节日模式
 */
public class LHolidayFragment extends MVPBaseFragment<LHolidayContract.View, LHolidayPresenter> implements LHolidayContract.View {
    @BindView(R.id.indicator)
    MagicIndicator mIndicator;
    @BindView(R.id.recycler_view)
    RecyclerView mRView;

    @Override
    protected Object getLayout() {
        return R.layout.fragment_holiday;
    }

    @Override
    protected void initLazy(Bundle savedInstanceState) {
        mPresenter.initData();

        initRecycler(mRView, 1, R.color.c_EEEEEE, false, true);

        LHolidayAdapter adapter = new LHolidayAdapter(null);
        adapter.bindToRecyclerView(mRView);

        View view = LayoutInflater.from(getProxyActivity()).inflate(R.layout.layout_empty_detail, null);
        adapter.setEmptyView(view);
    }

    @Override
    public void inflateTab(List<String> tabList) {
        magic3(tabList);
    }

    private void magic3(final List<String> titles) {
        final int blue = ResUtil.getColor(getProxyActivity(), R.color.c_3862FF);
        final int gray = ResUtil.getColor(getProxyActivity(), R.color.c_666666);

        final CommonNavigator commonNavigator2 = new CommonNavigator(getProxyActivity());

        FragmentContainerHelper helper = new FragmentContainerHelper(mIndicator);
        helper.handlePageSelected(0);

        commonNavigator2.setAdapter(new CommonNavigatorAdapter() {
            @Override
            public int getCount() {
                return titles == null ? 0 : titles.size();
            }

            @Override
            public IPagerTitleView getTitleView(Context context, final int index) {
                SimplePagerTitleView tvTitle = new ColorFlipPagerTitleView(context);
                tvTitle.setText(titles.get(index));
                tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11);
                tvTitle.setNormalColor(gray);
                tvTitle.setSelectedColor(Color.WHITE);
                tvTitle.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        helper.handlePageSelected(index);
                    }
                });
                return tvTitle;
            }

            @Override
            public IPagerIndicator getIndicator(Context context) {
                WrapPagerIndicator indicator = new WrapPagerIndicator(context);
                indicator.setHorizontalPadding(9);
                indicator.setVerticalPadding(2);
                indicator.setFillColor(blue);
                return indicator;
            }

        });
        mIndicator.setNavigator(commonNavigator2);

    }
}
